package aaa.update;

import java.util.ArrayList;

import aaa.schedule.UpdateListener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class UpdateNotifier extends BroadcastReceiver {

	protected static ArrayList<UpdateListener> listeners 
		= new ArrayList<UpdateListener>() ;
	
	public static void addListener(UpdateListener listener) {
		listeners.add(listener) ;
	}// addListener(UpdateListener)
	
	public static void removeListener(UpdateListener listener) {
		listeners.remove(listener) ;
	}// removeListener(UpdateListener)
	
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d("aaa", "--------------------") ;
		Log.d("aaa", "BroadCast received !") ;
		Log.d("aaa", "Context : "+context) ;
		Log.d("aaa", "Intent : "+intent) ;
		Bundle extras = intent.getExtras() ;
		String key = "aaa.schedule.name" ;
		Log.d("aaa", "  "+key+" -> "+extras.getString(key)) ;
		key = "aaa.schedule.status" ;
		Log.d("aaa", "  "+key+" -> "+extras.getInt(key)) ;
		Log.d("aaa" ,"Running in thread : "+Thread.currentThread()) ;
//		Bundle extras = intent.getExtras() ;
		for(UpdateListener listener : this.listeners) {
			listener.onUpdate(extras.getString("aaa.schedule.name"), extras.getInt("aaa.schedule.status")) ;
		}// for
	}

}
